package handler

import (
	"context"
	"fmt"
	"monitor_serve/service"
	"monitor_serve/service/account/proto/userpb"
)

type User struct {
}

func (u *User) SignUp(c context.Context, req *userpb.ReqSignup, res *userpb.RespSignup) error {
	username := req.Username
	password := req.Password
	// 2. 检查用户名和密码长度
	if len(username) < 4 || len(password) < 4 {
		res.Code = 403
		res.Message = "注册参数无效"
		return nil
	}
	if err := service.ServiceGroupApp.UserService.UserSignUp(username, password); err != nil {
		res.Code = 403
		res.Message = "注册失败"
		fmt.Println(err)
		return nil
	}
	res.Code = 200
	res.Message = "注册成功"
	return nil
}
